#include <iostream>
#include <cstring>

using namespace std;
const int N = 7;

int id[N];
int n;
int main() 
{
    cin >> n;
    memset(id, -1, sizeof id);
    id[0] = 0;
    int sum = 0, ret = 0;
    for (int i = 1; i <= n; i++)
    {
        int x; cin >> x;
        sum = (sum + x) % 7;
        if (id[sum] != -1) ret = max(ret, i - id[sum]);
        else id[sum] = i;
    }

    cout << ret << endl;
    return 0;
}